package cn.seecoder.ai.controller;

import cn.seecoder.ai.model.vo.ConfigVO;
import cn.seecoder.ai.model.vo.ResultVO;
import cn.seecoder.ai.service.ConfigService;
import cn.seecoder.ai.service.FileInfoService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author fanyanpeng
 * @date 2023/4/14 22:09
 */
@Slf4j
@RestController
@RequestMapping("${apiPrefix}/ml/configs")
public class ConfigController {

    @Autowired
    ConfigService configService;

    @Autowired
    FileInfoService fileInfoService;

    @ApiOperation("创建配置")
    @PostMapping("")
    public ResultVO<ConfigVO> createConfig(@RequestBody ConfigVO configVO){
        log.info("configVO fetched: {}",configVO.toString());
        configVO = configService.createConfig(configVO);
        return ResultVO.buildSuccess(configVO);
    }

    @ApiOperation("获取用户配置列表")
    @GetMapping("")
    public ResultVO<List<ConfigVO>> getConfigList(@RequestParam Integer userId){
        return ResultVO.buildSuccess(configService.getConfigList(userId));
    }

    @ApiOperation("查看配置详细信息")
    @GetMapping("/{configId}")
    public ResultVO<ConfigVO> getConfig(@RequestParam Integer userId, @PathVariable Integer configId){
        return ResultVO.buildSuccess(configService.getConfig(userId,configId));
    }

    @ApiOperation("删除配置")
    @DeleteMapping("/{configId}")
    public ResultVO<Boolean> deleteConfig(@RequestParam Integer userId, @PathVariable Integer configId){
        return ResultVO.buildSuccess(configService.deleteConfig(userId, configId));
    }

    @ApiOperation("自动特征选择")
    @PostMapping("/auto")
    public ResultVO<List<String>> autoChooseFeatures(@RequestParam(value = "userId") Integer userId,
                                                     @RequestParam(value = "fileId") Integer fileId,
                                                     @RequestParam(value = "label") String label){
        return ResultVO.buildSuccess(fileInfoService.autoChooseFeatures(userId,fileId,label));
    }

}
